package com.tanjie.blackbean.system.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tanjie.blackbean.mybatis.query.PageParam;
import com.tanjie.blackbean.system.admin.model.role.RoleBindMenuPermissionDTO;
import com.tanjie.blackbean.system.admin.model.role.RoleDTO;
import com.tanjie.blackbean.system.admin.model.role.RoleQuery;
import com.tanjie.blackbean.system.admin.model.role.RoleVO;
import com.tanjie.blackbean.system.admin.service.IRoleService;
import com.tanjie.blackbean.web.annotation.BlackBeanController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

/**
 * 角色表
 *
 * @author tanjie
 * @since 2022-04-20
 */
@Tag(name = "角色表")
@BlackBeanController
@RequestMapping("role")
public class RoleController {

    @Resource
    IRoleService roleService;

    @Operation(summary = "新增")
    @PostMapping("create")
    public void createSysRoleHandler(@RequestBody @Validated RoleDTO dto) {
        roleService.create(dto);
    }

    @Operation(summary = "更新")
    @PostMapping("update")
    public void updateSysRoleHandler(@RequestBody @Validated RoleDTO dto) {
        roleService.update(dto);
    }

    @Operation(summary = "删除")
    @GetMapping("delete")
    public void deleteSysRoleHandler(String id) {
        roleService.delete(id);
    }

    @Operation(summary = "获取详情")
    @GetMapping("detail")
    public RoleVO getSysRoleDetailHandler(String id) {
        return roleService.detail(id);
    }

    @Operation(summary = "列表查询")
    @PostMapping("list")
    public List<RoleVO> querySysRoleListHandler(@RequestBody(required = false) RoleQuery dto) {
        return roleService.queryList(dto);
    }

    @Operation(summary = "获取当前用户组织机构下的所有角色")
    @GetMapping("list")
    public List<RoleVO> getOrgRoleListHandler() {
        return roleService.getOrgRoleList();
    }

    @Operation(summary = "分页查询")
    @PostMapping("page")
    public IPage<RoleVO> queryPageListHandler(@RequestBody(required = false) RoleQuery dto, PageParam pageParam) {
        return roleService.queryPage(dto, pageParam);
    }

    // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    @Operation(summary = "角色绑定菜单和权限")
    @PostMapping("bindMenuPermission")
    public void bindMenuPermissionHandler(@RequestBody @Validated RoleBindMenuPermissionDTO dto) {
        roleService.bindMenuPermission(dto);
    }

}
